#include "led_control.h"
#include <Arduino.h>

// Variables to store the high and low states based on LED type
static int highState;
static int lowState;

// Initialize LED pin with active level judgment
void initLed(int ledPin, bool isLowActive) {
  if (!isLowActive) {
    highState = HIGH;
    lowState = LOW;
  } else {
    highState = LOW;
    lowState = HIGH;
  }
  pinMode(ledPin, OUTPUT);
}

// Blink LED with specified delay
void blinkLed(int ledPin, unsigned long delayTime) {
  digitalWrite(ledPin, !digitalRead(ledPin));
  delay(delayTime);
}

// Turn LED on
void turnLedOn(int ledPin) {
  digitalWrite(ledPin, highState);
}

// Turn LED off
void turnLedOff(int ledPin) {
  digitalWrite(ledPin, lowState);
}

led_control_opt_t led_control_opt = {
    .init= initLed,
    .blink = blinkLed,
    .turn_on = turnLedOn,
    .turn_off = turnLedOff
};